/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.order;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.hutech09.jsale.bsn.IOrderManager;
import org.hutech09.jsale.entity.OrderDetail;
import org.hutech09.jsale.entity.POrder;
import org.hutech09.jsale.entity.Product;
import org.hutech09.jsale.web.customer.cusController;
import org.hutech09.jsale.web.product.cartController;
import org.hutech09.jsale.web.product.productModel;

/**
 *
 * @author abc
 */
@ManagedBean
@SessionScoped
public class orderController {

    @EJB
    private IOrderManager iOrderManager;
     @ManagedProperty(value = "#{cusController}")
        private cusController cusController;
      @ManagedProperty(value = "#{cartController}")
        private cartController cartController1;

    public cartController getCartController1() {
        return cartController1;
    }

    public void setCartController1(cartController cartController1) {
        this.cartController1 = cartController1;
    }
      
     private POrder order;
     private List<OrderDetail> listorderDetails = new ArrayList<OrderDetail>();

    public List<OrderDetail> getListorderDetails() {
        return listorderDetails;
    }

    public void setListorderDetails(List<OrderDetail> listorderDetails) {
        this.listorderDetails = listorderDetails;
    }
     
    public POrder getOrder() {
        return order;
    }

    public void setOrder(POrder order) {
        this.order = order;
    }
     

    public cusController getCusController() {
        return cusController;
    }

    public void setCusController(cusController cusController) {
        this.cusController = cusController;
    }
    public void order(){
        
    }
    public String createOrder()
    {
         this.order = new POrder();
        order.setCreateDate(new Date());
        order.setCustomer(cusController.getCus());
        this.order= iOrderManager.createOrder(order);
        for (productModel pro : getCartController1().getCard().getListPromodel()) {
            OrderDetail orderdetail = new OrderDetail();
            orderdetail.setpOrder(order);
            orderdetail.setProduct(pro.getProdetail().getProduct());
            orderdetail.setAmount((int)pro.getSoluong());
            iOrderManager.createOrderDetail(orderdetail);
        }
        return "order";
    }
    public void getorderDetail()
    {
        listorderDetails = iOrderManager.getOrderDetail(order);
    }
    public orderController() {
    }
   
}
